local extension=Package("jbsheg_partner")
extension.extensionName="jbs2"
--extension.game_modes_whitelist = { 'nos_heg_mode', 'new_heg_mode' ,"jbsnew_heg_mode"}
local U = require "packages/utility/utility"
local T = require "packages/jbs/record/Theorem"
local H = require "packages/hegemony/util"
Fk:loadTranslationTable{
    ["jbsheg_partner"]="群友",
    
}

local zhoupeng=T.creategenandtanslatene({extension,"jbsheg_partner__zhoupeng","ws",4},{"周鹏","逆天之祖"})
T.skilltranslate("jhp_nitian",{"逆天",[[摸牌阶段，你可以少摸一张牌，与一名其他角色交换副将。]]})



--- 交换副将
---@param room Room
---@param player ServerPlayer
---@param target ServerPlayer
---@return boolean
local function SwapDeputys(room, player,target)
    local general1 = player.deputyGeneral
    local general2 = target.deputyGeneral
    if not (general1 and general2) then return false end
    if general1 == "anjiang" then player:revealGeneral(false, true) end
    if general2 == "anjiang" then target:revealGeneral(true, true) end
    general1 = player.deputyGeneral
    general2 = target.deputyGeneral
    if string.find(general1, "lord") 
     or string.find(general1, "zhonghui") or string.find(general1, "simazhao") 
     or string.find(general1, "sunchen") or string.find(general1, "gongsunyuan") 
    then return false end
    room:changeHero(player, "blank_shibing", false, true, false, false, false)
    room:changeHero(player, general2, false, true, true, false, false)
    room:changeHero(target, general1, false, true, true, false, false)
    return true
  end


local jhp_nitian = fk.CreateTriggerSkill{
  name = "jhp_nitian",
  anim_type = "control",
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)  and data.n > 0 and
      table.find(player.room:getOtherPlayers(player, false), function(p) return  H.hasGeneral(p, true)end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room:getOtherPlayers(player, false), function(p)
      return H.hasGeneral(p, true) end), Util.IdMapper)

    local result = room:askForChoosePlayers(player, targets, 1, 1, "#nitian-ask", self.name)
    if #result > 0 then
      self.cost_data = result
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, id in ipairs(self.cost_data) do
      if player.dead then return end
      local p = room:getPlayerById(id)
      if not p.dead and  H.hasGeneral(p, true) then
        SwapDeputys(room, player,p)
      end
    end
    data.n=data.n-1
  end,
}

zhoupeng:addSkill(jhp_nitian)

return extension